package com.example.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;


/***
 *
 * Redis监听消息过期事件，不可靠，不建议使用。
 */
@Deprecated
@Service
public class KeyExpiredListener extends KeyExpirationEventMessageListener {

    Logger logger = LoggerFactory.getLogger(getClass());

    public KeyExpiredListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        logger.warn("key: " + new String(message.getBody(), StandardCharsets.UTF_8));
    }
}